<?php

$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
set_include_path(get_include_path().PATH_SEPARATOR.$baseDir.PATH_SEPARATOR.$baseDir.'/incubator');

include '../../testingfunctions.php';
include 'Pone/Pone_Exception.php';
include 'Pone/Database/Pone_Database_ConnectionFactory.php';
include_once './dbconfig.php'; // $config is defined here
include_once './test_setup.php'; // refreshTestData() is defined here

try
{
    refreshTestData($config);
    // /home/web/windows.php.net/docroot/downloads/snaps/
    $conn    = Pone_Database_ConnectionFactory::getConnection($config);
    $stmt    = $conn->createStatement();
    $success = $stmt->execute('SELECT username FROM test2 WHERE id = 4');
    $rs      = $stmt->getResultSet();
    assertTrue($success === true, 'Expected: A boolean value. ');
    echo '<br />';
    assertTrue($rs instanceof Pone_Database_ResultSetInterface, 'Expected: An instance of Pone_Database_ResultSetInterface. ');
    echo '<br />';
    assertTrue($rs->currentRowNumber() === 0, 'Expected: 0 (before first row)');
    echo '<br />';
    $hasNext = $rs->next();
    assertTrue($rs->currentRowNumber() === 1, 'Expected: 1 (first row). ');
    echo '<br />';
    $hasNext = $rs->next();
    assertTrue($hasNext === false, 'Expected: false (no row can be fetched) ');
    // Free resources
    $stmt->close();
}
catch (Pone_Exception_DatabaseAccess $ex)
{
    echo implode('. ', $ex->getTraceMessages());
    echo '<br />';
    echo $ex->getNativeMessage();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}

$conn->close();
?>